package com.harmontronics.hanma.paas.paas.domain.job.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.domain.job.repository.persistence.HmSysJobLogRepository;
import com.harmontronics.hanma.paas.paas.domain.job.entity.HmSysJobLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.common.PageBase;

import com.harmontronics.hanma.paas.paas.domain.job.repository.mapper.HmSysJobLogMapper;
import com.harmontronics.hanma.paas.paas.domain.job.repository.po.HmSysJobLogPO;
import java.util.List;

@Service("hmSysJobLogService")
@DS("#header.App-Unique")
public class HmSysJobLogService {

    @Autowired
    private HmSysJobLogRepository hmSysJobLogRepository;

    @Autowired
    private HmSysJobLogMapper hmSysJobLogMapper;


    public HmSysJobLog findById( Long jobLogId) {
            HmSysJobLogPO po = hmSysJobLogRepository.getById(jobLogId);
        return BeanUtil.toBean(po,HmSysJobLog. class);
    }

    public void save(HmSysJobLog hmSysJobLog) {
            HmSysJobLogPO po = BeanUtil.toBean(hmSysJobLog,HmSysJobLogPO.class);
            hmSysJobLogRepository.save(po);
    }

    public void update(HmSysJobLog hmSysJobLog) {
            HmSysJobLogPO po = BeanUtil.toBean(hmSysJobLog,HmSysJobLogPO.class);
            hmSysJobLogRepository.updateById(po);
    }

    public void remove(List<Long> ids) {
            hmSysJobLogRepository.removeByIds(ids);
    }

    public List<HmSysJobLog> getList() {
        List<HmSysJobLogPO> pos = hmSysJobLogRepository.list();
        return Convert.toList(HmSysJobLog. class,pos);
    }

    public PageBase<HmSysJobLog> getList(int pageNo, int pageSize) {
        Page<HmSysJobLogPO> page = new Page<>(pageNo, pageSize);
        IPage<HmSysJobLogPO> resultPage =
                    hmSysJobLogRepository.selectPage(Wrappers.emptyWrapper(), page);
        return PageBase.from(resultPage,HmSysJobLog. class);
    }

    public IPage<HmSysJobLog> list(IPage<HmSysJobLog> page, HmSysJobLog sysJobLog) {
        return page.setRecords(hmSysJobLogMapper.list(page, sysJobLog));
    }

}